home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / PowerMacOberon feb96 / Text / Prog.Guide.Text (.txt) < prev    next >
Encoding:
Oberon Text  |  1995-06-09  |  36.4 KB  |  792 lines  |  [TEXT/.Ob4]

  1. Syntax10.Scn.Fnt
  2. StyleElems
  3. Alloc
  4. Header
  5. Palatino18b.Scn.Fnt
  6. Palatino18.Scn.Fnt
  7. Palatino14.Scn.Fnt
  8. Palatino10.Scn.Fnt
  9. BalloonElems
  10. Alloc
  11. Syntax10.Scn.Fnt
  12. right interclick to edit menu
  13. Text1
  14. Palatino14b.Scn.Fnt
  15. FoldElems
  16. Palatino20b.Scn.Fnt
  17. TwoCols
  18. LinkElems
  19. Alloc
  20. Prog.Guide.Text
  21. Prog.Guide.Text
  22. Prog.Guide.Text
  23. Palatino10i.Scn.Fnt
  24. Prog.Guide.Text
  25. Prog.Guide.Text
  26. Prog.Guide.Text
  27. Prog.Guide.Text
  28. Prog.Guide.Text
  29. Prog.Guide.Text
  30. Prog.Guide.Text
  31. Prog.Guide.Text
  32. Prog.Guide.Text
  33. Text1
  34. TwoCols
  35. Prog.Guide.Text
  36. Prog.Guide.Text
  37. Prog.Guide.Text
  38. Prog.Guide.Text
  39. Prog.Guide.Text
  40. Prog.Guide.Text
  41. Prog.Guide.Text
  42. Prog.Guide.Text
  43. Prog.Guide.Text
  44. Prog.Guide.Text
  45. Text1
  46. TwoCols
  47. Palatino10.Scn.Fnt
  48. Palatino10i.Scn.Fnt
  49. ---------------
  50. Most Oberon viewers have 2 frames (a menu frame and a contents frame). Such viewers are opened with MenuViewers.New instead of Viewers.Open. MenuViewers.New needs the following parameters:
  51. - a menu frame
  52. - a contents frame
  53. - the height of the menu (usually always TextFrames.menuH)
  54. - the coordinates of a point on the upper edge of the new viewer
  55. ---------------
  56. Palatino10.Scn.Fnt
  57. Palatino10i.Scn.Fnt
  58. ---------------
  59. A viewer is normally closed interactively with the command System.Close. It can, however, also be closed from a program with Viewers.Close. The contents of the viewer is not saved automatically. A viewer that was closed unintentionally can be reopened with the command System.Recall.
  60. ---------------
  61. MarkElems
  62. Alloc
  63. Palatino10.Scn.Fnt
  64. Syntax10.Scn.Fnt
  65. Palatino10i.Scn.Fnt
  66. FoldElems
  67. Syntax10.Scn.Fnt
  68. Viewers.This(x, 0)
  69. Syntax10.Scn.Fnt
  70. v.state > 1
  71. Syntax10.Scn.Fnt
  72. Viewers.Next(v)
  73. Syntax10.Scn.Fnt
  74. x + v.W
  75. ---------------
  76. This can be useful for finding a specific viewer or a viewer with a certain contents.
  77. PROCEDURE TraverseAllViewers;
  78.     VAR x: INTEGER; v: Viewers.Viewer;
  79. BEGIN
  80.     x := 0;
  81.     WHILE x < Display.Width DO
  82.         v := 
  83. bottom viewer in x track
  84.         WHILE 
  85. v is not the filler viewer
  86.             (*... process viewer v ...*)
  87.             v := 
  88. viewer above v
  89.         END;
  90.         x := 
  91. x of next track
  92. END TraverseAllViewers;
  93. ---------------
  94. Palatino10.Scn.Fnt
  95. ---------------
  96. This message is normally forwarded to the frames of the viewer.
  97. ---------------
  98. Palatino10.Scn.Fnt
  99. LinkElems
  100. Alloc
  101. MyProg.Guide.Text
  102. Palatino10i.Scn.Fnt
  103. Syntax10.Scn.Fnt
  104. ---------------
  105. Traverse all viewers on the screen (
  106. ) and find the one with the smallest value of
  107. v.dsc.next(TextFrames.Frame).time.
  108. ---------------
  109. Text1
  110. Palatino14b.Scn.Fnt
  111. Syntax10.Scn.Fnt
  112. StyleElems
  113. Alloc
  114. TwoCols
  115. Palatino10.Scn.Fnt
  116. LinkElems
  117. Alloc
  118. Prog.Guide.Text
  119. Prog.Guide.Text
  120. Palatino10i.Scn.Fnt
  121. Prog.Guide.Text
  122. Prog.Guide.Text
  123. Prog.Guide.Text
  124. Prog.Guide.Text
  125. Prog.Guide.Text
  126. Prog.Guide.Text
  127. Prog.Guide.Text
  128. Prog.Guide.Text
  129. Prog.Guide.Text
  130. Position of star-shaped pointer    x := Oberon.Pointer.X;
  131.                 y := Oberon.Pointer.Y;
  132. The marked viewer    Oberon.MarkedViewer()
  133. Position of the mouse    x := Oberon.Mouse.X;
  134.                 y := Oberon.Mouse.Y;
  135. Viewer which contains mouse    Viewers.This(Oberon.Mouse.X, Oberon.Mouse.Y)
  136. Focus viewer    Oberon.FocusViewer
  137. Is viewer v a standard text viewer?    IF (v IS MenuViewers.Viewer) &
  138.                     (v.dsc IS TextFrames.Frame) &
  139.                     (v.dsc.next IS TextFrames.Frame) THEN ...
  140. Has viewer v a text frame as menu frame?    IF v.dsc IS TextFrames.Frame THEN ...
  141. Has viewer v a text frame as main frame?    IF (v.dsc # NIL) &
  142.                     (v.dsc.next IS TextFrames.Frame) THEN ...
  143. The menu frame of a text viewer v    v.dsc(TextFrames.Frame)
  144. The menu text of a text viewer v    v.dsc(TextFrames.Frame).text
  145. The main frame of a text viewer v    v.dsc.next(TextFrames.Frame)
  146. The main text of a text viewer v    v.dsc.next(TextFrames.Frame).text
  147. The most recent selection    Oberon.GetSelection(text, beg, end, time)
  148. Is the command executed from the menu    v := Oberon.Par.vwr;
  149.     frame?    IF (Oberon.Par.frame IS TextFrames.Frame) &
  150.                     (v.dsc = Oberon.Par.frame) THEN ...
  151. Placement of the viewer in the user track    Oberon.AllocateUserViewer(
  152.     of the display which contains the mouse        Oberon.Mouse.X, x, y)
  153. Placement of the viewer in the system track    Oberon.AllocateSystemViewer(
  154.     of the display which contains the mouse        Oberon.Mouse.X, x, y)
  155. Open a new text viewer: x and y are     text := TextFrames.Text(name);
  156.     determined by AllocateUserViewer or    v := MenuViewers.New(
  157.     AllocateSystemViewer        TextFrames.NewMenu(name, cmds),
  158.                     TextFrames.NewText(text, 0),
  159.                     TextFrames.menuH, x, y)
  160. Open a viewer    
  161. Text1
  162. Palatino14b.Scn.Fnt
  163. Syntax10.Scn.Fnt
  164. StyleElems
  165. Alloc
  166. TwoCols
  167. Palatino10.Scn.Fnt
  168. Palatino10i.Scn.Fnt
  169. LinkElems
  170. Alloc
  171. Prog.Guide.Text
  172. Prog.Guide.Text
  173. Prog.Guide.Text
  174. Prog.Guide.Text
  175. Prog.Guide.Text
  176. Prog.Guide.Text
  177. Prog.Guide.Text
  178. Prog.Guide.Text
  179. Prog.Guide.Text
  180. Prog.Guide.Text
  181. Has viewer v a main frame?    IF (v.dsc # NIL) &
  182.                     (v.dsc.next IS TextFrames.Frame) THEN ...
  183. The focus viewer    Oberon.FocusViewer
  184. Text of text frame f    f.text
  185. Position of first displayed character    f.org
  186. A caret is set in text frame f    IF f.hasCar THEN ...
  187. Position of the caret, if one is set    IF f.hasCar THEN pos := f.carloc.pos END;
  188. A selection exists in text frame f    IF f.hasSel THEN ...
  189. Start of the selection, if one exists    IF f.hasSel THEN pos := f.selbeg.pos END;
  190. End of the selection, if one exists    IF f.hasSel THEN pos := f.selend.pos END;
  191. Set the caret at pos in text frame f    Oberon.PassFocus(v);
  192.     installed in menu viewer v    TextFrames.SetCaret(f, beg, end);
  193. Select stretch [beg, end) in text frame f    TextFrames.SetSelection(f, beg, end);
  194. Scroll text such that line with origin at org    TextFrames.RemoveSelection(f);
  195.     will be displayed on top of the viewer    TextFrames.RemoveCaret(f);
  196.                 Oberon.RemoveMarks(f.X, f.Y, f.W, f.H);
  197.                 TextFrames.Show(f, org);
  198. Delete the selected text in the marked viewer    
  199. Copy the most recent selection to the caret's position    
  200. A caret is only allowed if the viewer which manages the frame is the focus viewer.
  201. If a caret is displayed (f.car > 0), it must be removed prior to using TextFrames.SetCaret.
  202. Prior to using TextFrames.Show, the caret, the selection, the mouse cursor, and the pointer must be removed.
  203. The Caret is removed either by a call of TextFrames.RemoveCaret(f) or as a consequence of Oberon.PassFocus(v).
  204. Text1
  205. Palatino14b.Scn.Fnt
  206. Syntax10.Scn.Fnt
  207. StyleElems
  208. Alloc
  209. TwoCols
  210. Palatino10.Scn.Fnt
  211. Palatino10i.Scn.Fnt
  212. LinkElems
  213. Alloc
  214. Prog.Guide.Text
  215. Prog.Guide.Text
  216. Prog.Guide.Text
  217. Prog.Guide.Text
  218. Prog.Guide.Text
  219. Prog.Guide.Text
  220. Prog.Guide.Text
  221. Open a new file name    f := Files.New(name);
  222. Open an existing file name    f := Files.Old(name);
  223. Write buffers to disk sectors    Files.Close(f);
  224. Write buffers to disk and register file f in directory    Files.Register(f);
  225. Sequential read access through rider r    Files.Set(r, f, 0);
  226.                 Files.Read(r, ch); Files.Read(r, ch);
  227. Sequential write access through rider r    Files.Set(r, f, 0);
  228.                 Files.Write(r, ch); Files.Write(r, ch);
  229. Random access at position pos    Files.Set(r, f, pos);
  230.                 Files.Read(r, ch); ... Files.Write(r, ch);
  231. Read/write a record a of type T    Files.ReadBytes(r, a, SIZE(T));
  232.                 Files.WriteBytes(r, a, SIZE(T));
  233. Read/write a record of type T accessed    Files.ReadBytes(r, p^, SIZE(T));
  234.     with a pointer p    Files.WriteBytes(r, p^, SIZE(T));
  235. Opening another rider for the same file    Files.Set(newR, Files.Base(r), Files.Pos(r))
  236. Text1
  237. Text1
  238. Palatino14b.Scn.Fnt
  239. Syntax10.Scn.Fnt
  240. StyleElems
  241. Alloc
  242. Text2
  243. Palatino10.Scn.Fnt
  244. Palatino10i.Scn.Fnt
  245. TwoCols
  246. Module In provides a set of basic routines for formatted input of characters, character sequences, numbers, and names. It assumes a standard input stream with a current position that can be reset. Usually the input stream is the text immediately following the most recently invoked command. If this text starts with the character ^ the current position is set to the beginning of the most recent selection (if no selection exists, Done is set to FALSE). If the text starts with the character * the current position is set to the beginning of the text in the marked viewer (if no viewer is marked, Done is set to FALSE). The end of the input stream is the end of the text containing the current position.
  247. Start reading process    In.Open or In.OpenText(t, pos)
  248. Read a character    In.Char(ch)
  249.     Usually you want to skip leading blanks    WHILE In.Done & (ch = " ") DO In.Char(ch) END;
  250. Read an integer number    In.Int(i) or In.LongInt(li)
  251. Read a real number    In.Real(r) or In.LongReal(lr)
  252. Read a name or a string    In.Name(s) or In.String(s)
  253. Read next symbol    IF In.Next() = In.name THEN
  254.     In.char, In.int, In.name, In.string,        In.Name(s)
  255.     In.real, In.longReal,    ELSIF In.Next() = In.string THEN
  256.     and In.inval        In.String(s)
  257.                 ELSE ...
  258. Determine success of the last operation    IF In.Done THEN ...
  259. Text1
  260. Palatino14b.Scn.Fnt
  261. Syntax10.Scn.Fnt
  262. StyleElems
  263. Alloc
  264. Text2
  265. Palatino10.Scn.Fnt
  266. Palatino10i.Scn.Fnt
  267. TwoCols
  268. Module Out provides a set of basic routines for formatted output of characters, numbers, and strings. It assumes a standard output stream to which the symbols are written.
  269. Start writing process    
  270.     Usually you want to write into the system log which does not need an Out.Open call.
  271.     Open a new output viewer    Out.Open
  272.     Redirect output to System.Log again    Out.Close
  273. Write a character    Out.Char(ch)
  274. Write an integer number    Out.Int(i, 0)
  275.     ... within 10 characters    Out.Int(i, 10)
  276. Write a real number    Out.Real(r, 0) or Out.LongReal(lr, 0)
  277. Write a string    Out.String(s)
  278. Write a new line character    Out.Ln
  279. Write a string containing one integer number    Out.F("$Value of x: #", x)
  280.     ... 2, 3, or 4 integer numbers    Out.F2("$x=#, y=#", x, y)
  281.     "$" is a new line character    Out.F3("$x=#, y=#, z=#", x, y, z)
  282.                 Out.F4("$x=#, y=#, a=#, b=#", x, y, a, b)
  283. Text1
  284. Palatino14b.Scn.Fnt
  285. Syntax10.Scn.Fnt
  286. StyleElems
  287. Alloc
  288. Text2
  289. Palatino10.Scn.Fnt
  290. Palatino10i.Scn.Fnt
  291. TwoCols
  292. LinkElems
  293. Alloc
  294. Prog.Guide.Text
  295. Prog.Guide.Text
  296. Module Input provides facilities to access the mouse, the keyboard, and the clock.
  297. Track the mouse    
  298. Try to read a character from keyboard    
  299. Get the time elapsed since system startup    seconds := Input.Time() DIV Input.TimeUnit
  300. Text1
  301.     Syntax10i.Scn.Fnt
  302. Syntax10.Scn.Fnt
  303. Syntax8i.Scn.Fnt
  304.     VAR text: Texts.Text;
  305. BEGIN
  306.     NEW(text); (* create an instance and install notifier *)
  307.     text.notify := TextFrames.NotifyDisplay;
  308.     Texts.Open(text, name); (* initialize text from file name *)
  309.     RETURN text
  310. END Text;
  311. Syntax10.Scn.Fnt
  312. Syntax8i.Scn.Fnt
  313. MarkElems
  314. Alloc
  315.     VAR r: Texts.Reader; ch: CHAR;
  316. BEGIN
  317.     IF pos < text.len THEN (* position is within the text *)
  318. Texts.OpenReader(r, text, pos);
  319.         Texts.Read(r, ch); (* read character at position pos *)
  320.         WHILE ~r.eot DO
  321.             (* process character ch *)
  322.             Texts.Read(r, ch)  (* read next character *)
  323.         END
  324. END ProcessText;
  325. Syntax10.Scn.Fnt
  326. Syntax8i.Scn.Fnt
  327. MarkElems
  328. Alloc
  329.     VAR r: Texts.Reader; ch: CHAR; Syntax10i: Fonts.Font;
  330. BEGIN
  331.     IF pos < text.len THEN
  332.         Syntax10i := Fonts.This("Syntax10i.Scn.Fnt");  (* the italics font *)
  333. Texts.OpenReader(r, text, pos);
  334.         Texts.Read(r, ch);  (* read first character *)
  335.         WHILE ~r.eot DO
  336.             IF r.fnt = Syntax10i THEN RETURN Texts.Pos(r) - 1 END;
  337.             Texts.Read(r, ch)  (* read next character *)
  338.         END
  339.     END;
  340.     RETURN -1
  341. END GetItalics;
  342. Syntax10.Scn.Fnt
  343. Syntax8i.Scn.Fnt
  344. MarkElems
  345. Alloc
  346.     VAR s: Texts.Scanner; ch: CHAR; name: ARRAY 256 OF CHAR; i: LONGINT;
  347. BEGIN
  348.     IF pos < text.len THEN (* position is within the text *)
  349. Texts.OpenScanner(s, text, pos);  (* set scanner to starting position *)
  350.         Texts.Scan(s);  (* scan a symbol *)
  351.         IF s.class = Texts.Name THEN
  352.             COPY(s.s, name)
  353.             (* process name *)
  354.         ELSIF s.class = Texts.Int THEN
  355.             i := s.i
  356.             (* process integer *)
  357.         END
  358. END ScanText;
  359. Syntax10.Scn.Fnt
  360. Syntax8i.Scn.Fnt
  361. MarkElems
  362. Alloc
  363. BEGIN
  364.     Texts.WriteString(w, txt);  (* append string txt to w.buf *)
  365.     Texts.WriteInt(w, i, 1);  (* convert i to text and append to w.buf *)
  366.     Texts.WriteLn(w);  (* append a carriage return character to w.buf *)
  367. Texts.Append(Oberon.Log, w.buf)  (* display w.buf in log *)
  368. END PutInt;
  369. Syntax10.Scn.Fnt
  370. MarkElems
  371. Alloc
  372. Syntax8i.Scn.Fnt
  373.     VAR s: Texts.Scanner; name: ARRAY 256 OF CHAR;
  374. BEGIN
  375. Texts.OpenScanner(s, 
  376. Oberon.Par.text, 
  377. Oberon.Par.pos);
  378.     Texts.Scan(s);
  379.     WHILE s.class = Texts.Name DO
  380.         COPY(name, s.s);
  381.         (* process object with name s.s *)
  382.         Texts.Scan(s)
  383. END ProcessNames;
  384. Syntax10.Scn.Fnt
  385. Syntax8i.Scn.Fnt
  386. MarkElems
  387. Alloc
  388.     VAR t: Texts.Text;  (* the text of the selection *)
  389.         beg, end: LONGINT;  (* the stretch in t which is selected *)
  390.         time: LONGINT;  (* the time of the most recent selection *)
  391. BEGIN
  392. Oberon.GetSelection(t, beg, end, time);
  393.     IF time > 0 THEN  (* the selection exists *)
  394.         (* process selection *)
  395. END ProcessSelection;
  396. Syntax10.Scn.Fnt
  397. Syntax8i.Scn.Fnt
  398. MarkElems
  399. Alloc
  400.     VAR s: Texts.Scanner; name: ARRAY 256 OF CHAR;
  401.         t: Texts.Text;  (* the text of the selection *)
  402.         beg, end: LONGINT;  (* the stretch in t which is selected *)
  403.         time: LONGINT;  (* the time of the most recent selection *)
  404. BEGIN
  405.     Texts.OpenScanner(s, 
  406. Oberon.Par.text, 
  407. Oberon.Par.pos);
  408.     Texts.Scan(s);
  409.     WHILE s.class = Texts.Name DO
  410.         COPY(name, s.s);
  411.         (* process object with name s.s *)
  412.         Texts.Scan(s)
  413.     END;
  414.     IF (s.class = Texts.Char) & (s.c = "^") THEN
  415.         Oberon.GetSelection(t, beg, end, time);
  416.         IF time > 0 THEN  (* the selection exists *)
  417.             Texts.OpenScanner(s, t, beg);
  418.             Texts.Scan(s);
  419.             IF s.class = Texts.Name THEN
  420.                 (* process object with name s.s *)
  421.             END
  422.         END
  423. END ProcessArgs;
  424. Syntax10i.Scn.Fnt
  425. Syntax10.Scn.Fnt
  426. MarkElems
  427. Alloc
  428.     VAR v: Viewers.Viewer; s: Texts.Scanner;
  429. BEGIN
  430.     Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos);
  431.     Texts.Scan(s);
  432.     IF (s.class = Texts.Char) & (s.c = "*") THEN
  433. v := Oberon.MarkedViewer();  (* does not require the star-shaped pointer to be visible *)
  434.         Viewers.Close(v)
  435. END Close;
  436. Syntax10i.Scn.Fnt
  437. Syntax10.Scn.Fnt
  438. MarkElems
  439. Alloc
  440.     VAR v: Viewers.Viewer; s: Texts.Scanner;
  441. BEGIN
  442.     Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos);
  443.     Texts.Scan(s);
  444.     IF (s.class = Texts.Char) & (s.c = "*") & Oberon.Pointer.on THEN  (* star-shaped must be visible *)
  445. v := Oberon.MarkedViewer(); 
  446.         Viewers.Close(v)
  447. END CloseVisible;
  448. Syntax10.Scn.Fnt
  449. Syntax8i.Scn.Fnt
  450. MarkElems
  451. Alloc
  452.     VAR f: TextFrames.Frame; t: Texts.Text; r: Texts.Reader; v: Viewers.Viewer;
  453.         beg, end, time: LONGINT;  (* time and stretch of selection *)
  454.         x, y: INTEGER;  (* position designated by the pointer *)
  455.         pos: LONGINT;  (* character equivalent of x, y *)
  456.         ch: CHAR;
  457. BEGIN
  458. Oberon.GetSelection(t, beg, end, time);  (* most recent selection *)
  459.     IF (time > 0)  (* selection exists *)
  460.         & Oberon.Pointer.on  (* pointer is visible *) THEN
  461. x := Oberon.Pointer.X; y := Oberon.Pointer.Y;
  462.         v := Viewers.This(x, y);  (* the viewer which contains the pointer *)
  463.         IF (v.dsc # NIL) & (v.dsc.next IS TextFrames.Frame) THEN  (* second frame is the text frame *)
  464. f := v.dsc.next(TextFrames.Frame);  (* the main frame *)
  465.             IF (y >= f.X) & (x < f.X + f.W) & (y >= f.Y) & (y < f.Y + f.H) THEN  (* pointer is in the main frame *)
  466.                 pos := TextFrames.Pos(f, x, y);  (* convert x, y to text position *)
  467.                 IF pos >= 0 THEN  (* position is valid *)
  468.                     Texts.OpenReader(r, f.text, pos);
  469.                     Texts.Read(r, ch);  (* read character at pos to access its font *)
  470.                     Texts.ChangeLooks(t, beg, end, {0}, r.fnt, 0, 0)  (* the font of the stretch [beg, end) is 
  471.                         changed and the display is updated *)
  472.                 END
  473.             END
  474.         END
  475.     END        
  476. END CopyFont;
  477. Syntax10.Scn.Fnt
  478. Syntax8i.Scn.Fnt
  479. MarkElems
  480. Alloc
  481.     VAR menuF, mainF: TextFrames.Frame;
  482.         txt: Texts.Text;  (* text of the main frame *)
  483.         v: MenuViewers.Viewer;
  484.         x, y: INTEGER;
  485. BEGIN
  486. txt := TextFrames.Text("");  (* create an empty text *)
  487.     menuF := TextFrames.NewMenu("New Viewer", "System.Close System.Copy System.Grow Edit.Store");
  488.     mainF := TextFrames.NewText(txt, 0);
  489. Oberon.AllocateUserViewer(Oberon.Mouse.X, x, y);  (* placement hint *)
  490. v := MenuViewers.New(menuF, mainF, TextFrames.menuH, x, y)
  491. END OpenViewer;
  492. Syntax10.Scn.Fnt
  493. Syntax10i.Scn.Fnt
  494. Syntax8i.Scn.Fnt
  495. MarkElems
  496. Alloc
  497.     VAR txt: Texts.Text;  (* text to be processed *)
  498.         v: Viewers.Viewer; s: Texts.Scanner;
  499. BEGIN
  500. v := Oberon.Par.vwr;
  501.     IF (Oberon.Par.frame IS TextFrames.Frame) & (Oberon.Par.frame = v.dsc) THEN  
  502.         (* command is issued from menu *)
  503.         IF (v.dsc # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
  504. txt := Oberon.Par.vwr.dsc.next(TextFrames.Frame).text
  505.             (* process text *)
  506.         END
  507.     ELSE (* command is issued from an editable text frame *)
  508.         Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos);
  509.         Texts.Scan(s);
  510.         WHILE s.class = Texts.Name DO
  511.             txt := TextFrames.Text(s.s);  (* open text from file with name s.s *)
  512.             (* process text *)
  513.             Texts.Scan(s)
  514.         END
  515.     END                    
  516. END ProcessText2;
  517. Syntax10.Scn.Fnt
  518. MarkElems
  519. Alloc
  520. Syntax8i.Scn.Fnt
  521.     VAR f: TextFrames.Frame; buf: Texts.Buffer; v: Viewers.Viewer; pos: LONGINT;
  522. BEGIN
  523. v := Oberon.FocusViewer;
  524.     IF (v.dsc # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
  525.         (* Focus viewer has a main frame which is a text frame. *)
  526.         f := v.dsc.next(TextFrames.Frame);  (* the main frame *)
  527. IF f.hasCar THEN  (* a caret is set *)
  528.             Texts.Recall(buf);  (* the most recently deleted text *)
  529.             pos := f.carloc.pos + buf.len;  (* caret position after insert *)
  530. Texts.Insert(f.text, f.carloc.pos, buf);
  531. TextFrames.SetCaret(f, pos)
  532.         END
  533. END Recall;
  534. Syntax10.Scn.Fnt
  535. MarkElems
  536. Alloc
  537. Syntax8i.Scn.Fnt
  538.     VAR v: Viewers.Viewer; pos, carPos: LONGINT; f: TextFrames.Frame;
  539. BEGIN
  540. v := Oberon.MarkedViewer();
  541.     IF (v.dsc # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
  542.         (* marked viewer has a main frame which is a text frame *)
  543. f := v.dsc.next(TextFrames.Frame);  (* the main frame *)
  544. IF f.hasCar THEN  (* a caret is displayed *)
  545.             carPos := f.carloc.pos
  546.         ELSE
  547.             carPos := 0
  548.         END;
  549.         pos := GetItalics(f.text, carPos);
  550.         IF pos < 0 THEN RETURN  (* no italics font found *)
  551.         ELSE
  552. Oberon.PassFocus(v);  (* request focus, clear caret if one is set *)
  553. TextFrames.RemoveSelection(f);
  554. Oberon.RemoveMarks(f.X, f.Y, f.W, f.H);
  555.             TextFrames.Show(f, pos - 200);  (* scroll viewer, positions the text near the top *)
  556. TextFrames.SetCaret(f, pos);  (* set the caret *)
  557.         END
  558. END SearchItalics;
  559. Syntax10.Scn.Fnt
  560. MarkElems
  561. Alloc
  562. Syntax8i.Scn.Fnt
  563. Syntax10i.Scn.Fnt
  564.     VAR file: Files.File;
  565. BEGIN
  566. file := Files.Old(name);  (* create file variable from directory entry name *)
  567.     IF file = NIL THEN  (* no entry name exists in the directory *)
  568. file := Files.New(name);  (* create new file *)
  569.     ELSE
  570.         (* process file *)
  571.     END;
  572.     (* ... *)
  573. Files.Register(file)  (* write buffers to disk and register file. In the case where the file is opened with Files.Old
  574.         there is no need to register the file, thus 
  575. Files.Close(f) would be enough. *)
  576.     (* The file is still valid after Files.Close or Files.Register is called! *)
  577. END ProcessFile;
  578. Syntax10.Scn.Fnt
  579.     VAR i, j: INTEGER;
  580. BEGIN
  581.     i := 0; j := 0;
  582.     LOOP
  583.         WHILE (name[i] # 0X) & (name[i] # ".") DO INC(i) END;
  584.         IF name[i] = 0X THEN EXIT END;
  585.         INC(i);
  586.         WHILE j # i DO bak[j] := name[j]; INC(j) END
  587.     END;
  588.     bak[j] := "B"; bak[j + 1] := "a"; bak[j + 2] := "k"; bak[j + 3] := 0X
  589. END Backup;
  590. Syntax10.Scn.Fnt
  591. Syntax8i.Scn.Fnt
  592.     VAR file: Files.File; bakName: ARRAY 32 OF CHAR; res: INTEGER;
  593. BEGIN
  594.     file := Files.New(name);  (* create an output file *)
  595.     (* ... *)
  596.     Backup(name, bakName);    (* create a backup name *)
  597.     Files.Rename(name, bakName, res);
  598.     CASE res OF
  599.         0:  (* file renamed *)
  600.     | 1: (* backup file already exists and is now associated with the old version of file name *)
  601.     | 2: (* name is not in directory *)
  602.     | 3: (* name is not well formed *)
  603.     END;
  604.     Files.Register(file)    (* register the newly created output file *)
  605. END Save;
  606. Syntax10.Scn.Fnt
  607. Syntax8i.Scn.Fnt
  608. MarkElems
  609. Alloc
  610.     TYPE
  611.         Person = POINTER TO PersonDesc;
  612.         PersonDesc = RECORD
  613.             Name: ARRAY 32 OF CHAR;
  614.             (* other fields *)
  615.         END;
  616.     VAR customer: Person;
  617.         r, w: Files.Rider; f: Files.File;
  618. BEGIN
  619.     f := Files.New("customer");
  620. Files.Set(r, f, 0);
  621.     Files.Set(w, f, 0);
  622.     (* ... *)
  623. Files.ReadBytes(r, customer^, SIZE(PersonDesc));  (* It is important to dereference the pointer *)
  624.     (* ... *)
  625. Files.WriteBytes(w, customer^, SIZE(PersonDesc));
  626.     (* ... *)
  627.     Files.Register(f)
  628. END RecordFile;
  629. Syntax10.Scn.Fnt
  630. Syntax10i.Scn.Fnt
  631.     VAR main: TextFrames.Frame; v: Viewers.Viewer;
  632. BEGIN
  633.     v := Oberon.MarkedViewer();
  634.     IF (v.dsc # NIL) & (v.dsc.next # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
  635.         main := v.dsc.next(TextFrames.Frame);    (* main text frame of marked viewer *)
  636.         IF main.hasSel THEN
  637.             Texts.Delete(main.text, main.selbeg.pos, main.selend.pos)
  638.         END
  639. END Delete;
  640. Syntax10.Scn.Fnt
  641. Syntax10i.Scn.Fnt
  642. FoldElems
  643. Syntax10.Scn.Fnt
  644. time >= 0
  645. Syntax10.Scn.Fnt
  646. (v.dsc # NIL) & (v.dsc.next IS TextFrames.Frame)
  647. Syntax10.Scn.Fnt
  648. main.hasCar
  649.     VAR main: TextFrames.Frame; buf: Texts.Buffer; v: Viewers.Viewer; beg, end, time: LONGINT; t: Texts.Text;
  650. BEGIN
  651.     Oberon.GetSelection(t, beg, end, time);    (* get most recent selection *)
  652. selection exists
  653.  THEN
  654.         NEW(buf); Texts.OpenBuf(buf);
  655.         Texts.Save(t, beg, end, buf);    (* save text in buffer *)
  656.         v := Oberon.FocusViewer;    (* get focus viewer *)
  657.         IF 
  658. it is a text viewer
  659.  THEN
  660.             main := v.dsc.next(TextFrames.Frame);    (* main text frame *)
  661.             IF 
  662. caret exists
  663.  THEN
  664.                 Texts.Insert(main.text, main.carloc.pos, buf)    (* insert text at caret's position *)
  665.             END
  666.         END
  667. END CopyText;
  668. Syntax10.Scn.Fnt
  669. Syntax10i.Scn.Fnt
  670.     VAR keys: SET;
  671. BEGIN
  672.     REPEAT
  673.         (* procress keysum and mouse position (x, y) *)
  674.         Input.Mouse(keys, x, y);
  675.         Oberon.DrawCursor(Oberon.Mouse , Oberon.Arrow, x, y);
  676.         keysum := keysum + keys
  677.     UNTIL keys = {}
  678. END TrackMouse;
  679. Syntax10.Scn.Fnt
  680. BEGIN
  681.     IF Input.Available() = 0 THEN RETURN FALSE END;
  682.     Input.Read(ch);
  683.     RETURN TRUE
  684. END ReadChar;
  685. PopupElems
  686. Alloc
  687. Commandos
  688. Syntax10.Scn.Fnt
  689. Sample.OpenViewer
  690. Sample.Recall
  691. Sample.SearchItalics
  692. Sample.Delete
  693. Sample.CopyText
  694. Programming Guide
  695. based on M. Reiser: "The Oberon System"
  696. ssenb
  697. ck, C. Mayrhofer, C. Steindl
  698. Working with texts
  699. System log text    Oberon.Log
  700. Create an empty text    text := TextFrames.Text("");
  701. Create a new text and initialize it from     text := TextFrames.Text(name);
  702.     disk file name
  703. Write to system log    
  704. Insert buffer buf at position pos in text    Texts.Insert(text, pos, buf);
  705. Append buffer buf to text    Texts.Append(text, buf);
  706. Read sequential characters    
  707. Scan sequential symbols    
  708. Save stretch [beg, end) of text in     NEW(buf); Texts.OpenBuf(buf);
  709.     buffer buf    Texts.Save(text, beg, end, buf);
  710. Create a text    
  711. Read from a text    
  712. Scan a text    
  713. Accessing parameters
  714. System parameter list    Oberon.Par
  715. Viewer from which command is issued    Oberon.Par.vwr
  716. Frame from which command is issued    Oberon.Par.frame
  717. Text from which command is issued    Oberon.Par.text
  718. Start of parameter list    Oberon.Par.pos
  719. The most recent selection in the system    Oberon.GetSelection(text, beg, end, time)
  720. The marked viewer    Oberon.MarkedViewer()
  721. Open scanner for parameter list    
  722. Was command issued from a menu    IF Oberon.Par.frame = Oberon.Par.vwr.dsc THEN
  723.     frame of any viewer?
  724. Parameters in the selection    
  725. The marked viewer as parameter    
  726. Menu commands implicitly refer to the viewer     
  727. which contains the menu frame.
  728. Viewers
  729. Opening a viewer   
  730.     v := MenuViewers.New(menuF, contF, menuH, x, y)
  731. Closing a viewer  
  732.     Viewers.Close(v)
  733. Finding the viewer at position (x, y)    v := Viewers.This(x, y)
  734. Traversing all viewers on the screen  
  735. Broadcasting a message to all viewers  
  736.     Viewers.Broadcast(msg)
  737. Getting the focus viewer    v := Oberon.FocusViewer
  738. Getting the marked viewer    v := Oberon.MarkedViewer()
  739. Getting the viewer containing the most recent text selection  
  740. Working with text viewers
  741. Working with text frames
  742. Working with files
  743. Input and Output
  744. Module In
  745. Module Out
  746. Module Input
  747. MODULE Sample;
  748. IMPORT Texts, TextFrames, Fonts, Oberon, Viewers, MenuViewers, Files, Input;
  749. VAR w: Texts.Writer;
  750. (* The following code is what TextFrames.Text actually does. *)
  751. PROCEDURE Text* (name: ARRAY OF CHAR): Texts.Text;
  752. (* Process all characters of a text, starting at position pos. *)
  753. PROCEDURE ProcessText (text: Texts.Text; pos: LONGINT);
  754. (* Searches a text from the initial position pos for the first occurrence of an italics font. It returns this position, if it exists, otherwise -1 results. *)
  755. PROCEDURE GetItalics (text: Texts.Text; pos: LONGINT): LONGINT;
  756. (* Scan a text, starting at position pos. *)
  757. (* When scanning a whole text, you can use ~s.eot as predicate in a WHILE loop as above, but s.eot may already yield TRUE while the last valid symbol is returned, not only after an attempt to scan beyond the end of the text. In this case, a WHILE loop using the predicate ~s.eot misses the last symbol. Therefore, it is always preferable to terminate a sequence of scan operations with a definite symbol. *)
  758. PROCEDURE ScanText (text: Texts.Text; pos: LONGINT);
  759. PROCEDURE PutInt* (txt: ARRAY OF CHAR; i: LONGINT);
  760. PROCEDURE ProcessNames*; (* {name} ~ *)
  761. PROCEDURE ProcessSelection*;  (* ^ *)
  762. PROCEDURE ProcessArgs*; (* {name} ~ | ^ *)
  763. PROCEDURE Close*; (* * *)
  764. PROCEDURE CloseVisible*; (* * *)
  765. (* Copies the font of the character underneath the star-shaped pointer to the selection *)
  766. PROCEDURE CopyFont*;
  767. PROCEDURE OpenViewer*;
  768. (* If the command is issued from an editable text, it admits a parameter list. All texts in the list will be processed. If, on the other hand, ProcessText2 is issued from the menu, it will work on the text contained in the main frame of the viewer which contains the menu. *)
  769. PROCEDURE ProcessText2*;
  770. (* The following code is what Edit.Recall actually does. *)
  771. PROCEDURE Recall*;
  772. (* The text of the main frame of the marked viewer is searched for the occurrence of a character in italics font Syntax10i.Scn.Fnt. The search is started at the caret position or at the beginning of the text if not caret is set. If a character is located, the text is scrolled such that it is displayed near the top line and the caret is positioned. *)
  773. PROCEDURE SearchItalics*;
  774. (* Try to open an old file, if none exists, create a new one *)
  775. PROCEDURE ProcessFile (name: ARRAY OF CHAR);
  776. PROCEDURE Backup (VAR name, bak: ARRAY OF CHAR);
  777. PROCEDURE Save (name: ARRAY OF CHAR);
  778. PROCEDURE RecordFile;
  779. (* Deletes the selected text in the marked viewer. *)
  780. PROCEDURE Delete*;
  781. (* Copies the most recently selected text part to the caret's position. *)
  782. PROCEDURE CopyText*;
  783. (* Tracks the mouse and process the mouse keys and the position *)
  784. PROCEDURE TrackMouse (VAR keysum: SET; VAR x, y: INTEGER);
  785. (* Try to read a character from keyboard *)
  786. PROCEDURE ReadChar (VAR ch: CHAR): BOOLEAN;
  787. BEGIN
  788.     Texts.OpenWriter(w)  (* The writer is based on the file system. In most cases, one writer per module is enough. It is, therefore, good practice to open the writer once per session in the module's body. *)
  789. END Sample.
  790. Compiler.Compile @/s
  791. ErrorElems.Mark    ErrorElems.Unmark    
  792.